<template>
  <div
    class="ui-panel"
    :class="[{'is-border': border}, 'ui-panel--' + size]"
  >
    <div class="ui-panel__head" v-if="icon || title || $slots.toolbar">
      <div class="ui-panel__head-left">
        <span class="ui-panel__icon" v-if="icon" :style="{'background-image': `url(${icon})`}"></span>
        <strong class="ui-panel__title" v-if="title">{{title}}</strong>
      </div>
      <div
        v-if="$slots.toolbar"
        class="ui-panel__head-right"
      >
        <slot name="toolbar"></slot>
      </div>
    </div>
    <div class="ui-panel__body">
      <slot></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: 'UiPanel',
  props: {
    title: {
      type: String
    },
    icon: {
      type: String
    },
    border: {
      type: Boolean,
      default: true
    },
    size: {
      type: String,
      default: 'small',
      validator (value) {
        return ['small', 'medium'].includes(value)
      }
    }
  }
}
</script>
<style lang="less">
.ui-panel{
  background-color: #fff;
  border-radius: 4px;
  &.is-border {
    border: 1px solid #e9edf0;
  }
}
.ui-panel__head {
  height: 32px;
  line-height: 32px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.ui-panel__icon{
  display: inline-block;
  width: 24px;
  height: 24px;
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: cover;
  margin-right: 6px;
}
.ui-panel__head-left{
  display: flex;
  flex-direction: row;
  align-items: center;
}
.ui-panel--small {
  .ui-panel__title {
    font-size: 14px;
  }
  &.is-border {
    > .ui-panel__head {
      padding: 12px 16px 0;
    }
    > .ui-panel__body {
      padding: 16px;
    }
    .ui-panel__head{
      + .ui-panel__body {
        padding-top: 12px;
      }
    }
  }
}
.ui-panel--medium {
  .ui-panel__title{
    font-size: 16px;
  }
  &.is-border {
    > .ui-panel__head {
      padding-top: 12px;
      padding-left: 20px;
      padding-right: 20px;
    }
    > .ui-panel__body {
      padding: 20px;
    }
    .ui-panel__head{
      + .ui-panel__body {
        padding-top: 12px;
      }
    }
  }
}
</style>
